<template>
	<up-notice-bar :text="text" speed="50"></up-notice-bar>
	<view class="container">
		<view class="reg_head">
			<text>上传视频认证</text>
		</view>
		<view class="userinfo">
			<up-form :model="form" label-width="90px">
				<up-form-item label="姓名" border-bottom prop="name">
					<up-input border="none" v-model="form.name" disabled disabledColor="#fff"></up-input>
				</up-form-item>
				<up-form-item label="身份证号" border-bottom prop="idCard">
					<up-input border="none" v-model="form.idCard" disabled disabledColor="#fff"></up-input>
				</up-form-item>
				<up-form-item label="人脸核身">
					<up-button type="primary" size="small" @click="auth">认证</up-button>
				</up-form-item>
			</up-form>
		</view>
	</view>
	<up-toast ref="uToastRef"></up-toast>
</template>

<script lang="ts" setup>
import { ref, reactive, nextTick } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import {
	getRealNameInfo
} from '@/api/user'
import {
	realAuth
} from '@/api/assignor'


/* 数据 */
const text = ref('人脸识别注意事项：1、人脸识别不在本小程序认证，需跳转其他小程序认证；2、人脸识别时请确保画面清晰，无遮挡，无抖动进行人脸识别；3、请确保网络稳定；4、人脸识别时请按提示进行操作。')
const uToastRef = ref<any>(null)
const form = reactive({
	name: '',
	idCard: '',
	realStatus: 'ASSIGNOR_REAL'
})



/* 方法 */
const auth = async () => {

	uToastRef.value.show({
		message: '正在获取您的信息',
		type: 'loading',
		duration: -1
	})
	let { data } = await getRealNameInfo({
		realStatus: 'ASSIGNOR_REAL'
	})
	uToastRef.value.hide()
	let flowId = data.data.flowId
	let bizToken = data.data.faceToken
	uni.navigateToMiniProgram({
		appId: 'wx1cf2708c2de46337',  // 上链公证签小程序APPID
		path: `/pages/face/index?bizToken=${bizToken}`,
		extraData: {
			requestObj: {  // 必填，入参
				flowId, // 必填，认证流程Id
				type: 'REALNAME'// 必填，业务类型：实名 REALNAME
			}
		}
	})
	return
}




/* 钩子 */
onLoad((options:any) => {
	form.name = options.name
	form.idCard = options.idCard
})
onShow(async () => {
	const options = uni.getEnterOptionsSync()
	await nextTick()
	if (options.referrerInfo.extraData.faceResult && options.referrerInfo.extraData.faceResult.ErrorCode === 0) {
		uToastRef.value.show({
			message: '认证中，请稍等',
			type: 'loading',
			duration: -1
		})
		let res = await realAuth(form)
		uToastRef.value.hide()
		if (res.success) {
			uToastRef.value.show({
				message: '认证成功',
				type: 'success',
				complete() {
					uni.reLaunch({
						url: '/pages/mine/index'
					})
				}
			})
		}
	}
})


</script>

<style lang="scss" scoped>
page {
	background-color: white;
}

.container {
	padding: 10px;
}



.userinfo {
	border-left: 4px solid #1890FF;
	box-shadow: 5px 5px 5px #ddd;
	border-radius: 6px;
	padding: 30rpx;
	margin-bottom: 50rpx;
}

.info_item {
	display: flex;
	margin-bottom: 30rpx;
}

.item_label {
	margin-right: 10rpx;
	font-size: 28rpx;
	line-height: 70rpx;
	width: 180rpx;
	text-align: right;
}

.item_ipt {
	width: 500rpx;
}

.item_ipt input {
	font-size: 28rpx;
	border-radius: 10rpx;
	border: 1px solid #ddd;
	height: 70rpx;
	line-height: 70rpx;
	padding: 0 20rpx;
	width: 500rpx
}

.item_ipt .input-placeholder {
	font-size: 28rpx;
	color: #999;
}

.pic_button {
	height: 70rpx;
	line-height: 70rpx;
	background: #1890FF;
	color: #fff;
	font-size: 30rpx;
	text-align: center;
	width: 300rpx;
	padding: 0;
	margin-left: 180rpx;
	display: block;
}

.reg_btn {
	height: 88rpx;
	line-height: 88rpx;
	background: #1890FF;
	color: #fff;
	font-size: 30rpx;
	border-radius: 999rpx;
	text-align: center;
	width: 80%;
	padding: 0;
	margin: 0 auto 30rpx;
}

.quit_btn {
	height: 88rpx;
	line-height: 88rpx;
	background: #dfdfdf;
	color: #fff;
	font-size: 30rpx;
	border-radius: 999rpx;
	text-align: center;
	width: 80%;
	padding: 0;
	margin: 0 auto 30rpx;
}

.info_item .img {
	border: 1px solid #ddd;
	width: 300rpx;
	height: 400rpx;
}

.reg_head {
	font-size: 28rpx;
	margin: 20rpx 0 50rpx 20rpx;
}
</style>
